import type { App } from 'vue'
import { useUserStore } from '@/store'

//按钮权限
export const installHasPermi = (app: App) => {
  app.directive('hasPermi', {
    mounted(el, binding) {
      const { permission } = useUserStore()
      const { value } = binding
      if (value && value instanceof Array && value.length > 0) {
        const hasPermi = value.some(item => permission.includes(item) || item == '')
        if (!hasPermi) el.parentNode && el.parentNode.removeChild(el)
      }
    }
  })
}
